/*
 * ModuleManager.h
 *
 *  Created on: 01.05.2009
 *      Author: h3llfire
 */

#ifndef MODULEMANAGER_H_
#define MODULEMANAGER_H_

#include <wx/string.h>
#include <vector>
#include "../interfaces/iModule.h"
#include "../interfaces/iChatWindow.h"
#include "../interfaces/iBuddyList.h"
#include "../interfaces/iUserInterface.h"

namespace Impp {


#define	MODULE_INTERFACE_MODULE 		wxT("iModule")
#define	MODULE_INTERFACE_BUDDYLIST 		wxT("iBuddyList")
#define	MODULE_INTERFACE_CHATWINDOW		wxT("iChatWindow")
#define	MODULE_INTERFACE_PROTCOL		wxT("iProtocol")
#define	MODULE_INTERFACE_USERINTERFACE	wxT("iUserInterface")

class ModuleInfo{
private:
	wxString moduleClassName;
	wxString interfaceClassName;
	iModule* module;
	bool inited;

public:
	ModuleInfo(const wxString & moduleClassName, const wxString & interfaceClassName);
	const wxString& getInterfaceClassName() const;
	const wxString& getClassName() const;

	iModule* getModule() const;
	bool loadModule();
	void initModule();
	void destroyModule();
	bool isLoaded() const;
	bool isInited() const;
};

class ProtocolInfo{

public:
	wxString className;

	iProtocol* createAndInitInstance(Account* account);

};

class ModuleManager {
private:
	ModuleInfo* userInterfaceModuleInfo;
	ModuleInfo* buddyListModuleInfo;
	ModuleInfo* chatWindowModuleInfo;

	std::vector<ModuleInfo*> modules;
	std::vector<ProtocolInfo*> protInfos;

public:
	ModuleManager();
	virtual ~ModuleManager();


	void loadAndInitCoreInterfaceModules();
	void destroyCoreInterfaceModules();
	void destroyOtherModules();

	size_t loadAndInit(const wxString & interfaceClassName);

	void addAvailableModul(const wxString & moduleClassName, const wxString & interfaceClassName);

	iBuddyList* getBuddyListModule();
	iUserInterface* getUserInterfaceModule();
	iChatWindow* getChatWindowModule();
	iModule* getModuleByInterface(const wxString & interfaceClassName);
	iModule* getModuleByClass(const wxString & className);

	void addAvailableProtocol(const wxString & className);
	iProtocol* loadAndInitProtocolInstance(Account* account);

private:
	void loadBuddyListModule();
	void loadUserInterfaceModule();
	void loadChatWindowModule();

	void initBuddyListModule();
	void initUserInterfaceModule();
	void initChatWindowModule();

	void destroyBuddyListModule();
	void destroyUserInterfaceModule();
	void destroyChatWindowModule();

};

}

#endif /* MODULEMANAGER_H_ */
